import type { Profile } from '@/types/user'
import { getLocalToken, setLocalToken,removeLocalToken } from '@/utils/auth'
import { defineStore } from 'pinia'
import {ref} from 'vue'

export const useUserStore = defineStore('hm-user', () => {

    const token=ref(getLocalToken()||'')
    const setToken=(val:string)=>{
      token.value=val
      setLocalToken(val)
    }

    const clearToken=() => {
      token.value = ''
      removeLocalToken()
    }

  // 用户信息
  const profile = ref<Profile>({} as Profile)
  // 设置用户信息 
  const setProfile = (val: Profile) => {
    profile.value = val
  }
  // 清空用户信息
  const clearProfile = () => {
    profile.value = {} as Profile
  }


    return {
      token,
      setToken,
      clearToken,
      setProfile,
      clearProfile,
      profile
    }

})
